﻿using UnityEngine;
using System.Collections;

public class GUIHex : MonoBehaviour {

	public GUIText GUILevel;
	public GUIText GUISkill;
	//public GUIText GUIValue1;
	//public GUIText GUIValue2;
	//public GUIText GUIValue3;
	public GUITexture Hex;
	public GUITexture Blob;
	public GUITexture Icon;

	//public int index;
	//public int value1;
	//public int value2;
	//public int value3;
	
	private PlayerColor color;
	private GameUnit unit;
	private GamePowerUp powerUp;
	
	// Use this for initialization
	void Start () {
		Blob.enabled = false;
	}
	
	// Update is called once per frame
	void Update () {
	}

	public float getWidth() {
		return Hex.pixelInset.width;
	}
	
	public float getHeight() {
		return Hex.pixelInset.height;
	}
	
	public bool hitTest(Vector2 pos) {
		//Debug.Log ("GUIHex.hitTest : rect=" + Hex.GetScreenRect ());
		return Hex.HitTest ( pos );
	}

	public void setSelected(bool selected) {
		Blob.enabled = selected;
	}
	
	public void setActive(bool value) {
		GUILevel.enabled = value;
		GUISkill.enabled = value;
		Icon.enabled = value;
		
		if (value) { //make sure everything is correctly restarted
			if (unit != null)
				setUnit(unit);
			else
				setPowerUp(powerUp);
		}
	}

	public void setUnit(GameUnit unit) {
		this.unit = unit;
		Icon.enabled = false;
		GUILevel.text = string.Format("{0}", unit.level);
		if (unit.skill == GameSkill.None)
			GUISkill.text = "";
		else
			GUISkill.text = string.Format("{0}:{1}", unit.skill, unit.skillLevel);
	}
	
	public GameUnit getUnit() {
		return this.unit;
	}
	
	public void setPowerUp( GamePowerUp powerUp ) {
		this.powerUp = powerUp;
		Icon.enabled = true;
		GUILevel.text = string.Format("{0}", powerUp.level);
		GUISkill.text = string.Format("{0}", powerUp.power);
	}
	
	public GamePowerUp getPowerUp() {
		return this.powerUp;
	}
	
	public void setColor(PlayerColor color) {
		// set the player color, hex color
		if (color == PlayerColor.Red)
			Hex.color = Color.red;
		else
			Hex.color = Color.blue;
	}

	/*public void setIndex(int index) {
		this.index = index;
	}
	
	public void setValues(int value1, int value2, int value3) {
		GUIValue1.text = string.Format("{0}", value1);
		GUIValue2.text = string.Format("{0}", value2);
		GUIValue3.text = string.Format("{0}", value3);

		this.value1 = value1;
		this.value2 = value2;
		this.value3 = value3;
	}*/
}
